#pragma once
#include <memory>
#include <iostream>
#include "const.h"
#include <boost/asio.hpp>
class MsgNode
{
public:
	//_data->[[<---_total_len--->']\0']
	MsgNode(short max_len) :_cur_len(0),_total_len(max_len+1){
		_data = new char[_total_len + 1];
		_data[_total_len] = '\0';
	}
	~MsgNode() {
		delete[] _data;
		std::cout << "~MsgNode()" << std::endl;
	}
	void Clear() {
		memset(_data, 0, _total_len);
		_cur_len = 0;
	}

	short _cur_len;
	short _total_len;
	char* _data;
};
class RecvNode :public MsgNode {
public:
	RecvNode(short msg_id, short msg_len) :MsgNode(msg_len), _msg_id(msg_id) {}
	~RecvNode(){}
	short _msg_id;
};
class SendNode :public MsgNode {
public:
	SendNode(short msg_id,const char* msg,short msg_len):MsgNode(msg_len+HEAD_TOTAL_LEN),_msg_id(msg_id){
		short net_msg_id = boost::asio::detail::socket_ops::host_to_network_short(msg_id);
		memcpy(_data,&net_msg_id, HEAD_ID_LEN);
		short net_msg_len = boost::asio::detail::socket_ops::host_to_network_short(msg_len);
		memcpy(_data+HEAD_ID_LEN,&net_msg_len, HEAD_DATA_LEN);
		memcpy(_data +HEAD_TOTAL_LEN,msg,msg_len);
	}
	~SendNode(){}
	short _msg_id;
};